;
(function() {

	var skill = {
		_getCoupon: function(coupon_id) {
			var coupons = this.coupons || [];
			if (coupons.indexOf(coupon_id) === -1) {
				throwCusError("优惠码不属于指定商家")
			}
			var coupon = CouponCon.get(coupon_id);
			if (!coupon) {
				throwCusError("找不到指定优惠码")
			}
			return coupon;
		},
		getCouponList: function(num, page) {
			var coupons = this.coupons || [];
			coupons = data_cut.page(coupons, num, page);
			coupons = coupons.map(function(coupon_id) {
				return CouponCon.get(coupon_id);
			});
			return coupons;
		},
		addCoupon: function(coupon_info) {
			var coupons = this.coupons || (this.coupons = []);
			if (coupons.length >= config.busCouponNumber) {
				throwCusError("商家同时的拥有优惠码数量已经达到上限")
			}
			var coupon = new CouponCon(coupon_info);
			var coupon_id = coupon._id
			coupons.unshift(coupon_id);
			this.save();
			return coupon_id;
		},
		add打折Coupon: function(coupon_info) {
			coupon_info.bus_id = this._id;
			/*现在限定这些参数，不开放*/
			// coupon_info.name = "【优惠码】折扣"//名字给予设定的能力
			coupon_info.times = Number.MAX_VALUE;
			coupon_info.diedline = Number.MAX_VALUE;
			coupon_info.type = CouponCon.TYPE.打折;
			coupon_info.intro = ""
			console.log(2, coupon_info);
			return this.addCoupon(coupon_info);
		},
		//优惠码暂时不给予修改功能，后面可能会加上是否发布参数，在发布之前还能做一定修改
		updateCoupon: function() {},
		removeCoupon: function(coupon_id) {
			var coupon = this._getCoupon(coupon_id);
			this.coupons = $Array.remove(this.coupons, coupon._id);
			coupon.destroy();
			this.save();
		},
	};
	module.exports = skill;
	var db = require("../db/index");
	var CouponCon = require("../coupon/_con");
	var DomainCon = require("../domain/_con");
	var GoodsCon = require("../goods/_con");
	var UserCon = require("../../core/user/_con");
	var BusCon = require("../../core/bus/_con");
	var AchCon = require("../ach/_con");
	var ClassifyCon = require("../bus.classify/_con");
	var TagCon = require("../bus.tag/_con");
	var LeagueCon = require("../league/_con");
	var BuffCon = require("../buff/_con");
	var BusUserBindCon = require("../bus_user_bind/_con");
	var BusGuideCon = require("../bus.guide/_con");
	var CommentCon = require("../comment/_con");
	var config = require("../_include/config");
	var data_cut = require("../_include/data_cut");
	var helper = require("../_include/helper");
	var md5 = require("../_include/md5");
	var $Object = require("../_include/$.Object");
	var $Array = require("../_include/$.Array");
	var tld = require('tldjs');
	var fs = require("fs");
	var Fiber = require('fibers');
}());